<template>
	<view>
		<view class="container" v-if="info.list.length">
			<view class="s-box">
				<s-list-cell :arrow="true" :last="true" :radius="true" @click="address">
					<view class="s-address">
						<view v-if="info.site_info">
							<view class="s-userinfo">
								<text class="s-name">{{info.site_info.name}}</text>{{info.site_info.phone}}
							</view>
							<view class="s-addr">
								<view class="s-addr-tag">默认</view>
								<text>{{info.site_info.province_name}}{{info.site_info.city_name}}{{info.site_info.county_name}}{{info.site_info.detailed_address}}</text>
							</view>
						</view>
						<view class="s-none-addr" v-else>
							<image src="/static/images/icon/map.png" class="s-addr-img" mode="widthFix"></image>
							<text>选择收货地址</text>
						</view>
					</view>
					<view class="s-bg-img"></view>
				</s-list-cell>
				<view class="s-top">
					<s-list-cell :hover="false" :lineLeft="false">
						<view class="s-goods-title">
							商品信息
						</view>
					</s-list-cell>
					<block v-for="(item,index) in info.list" :key="index">
						<s-list-cell :hover="false" padding="0">
							<view class="s-goods-item">
								<image :src="item.image_url" class="s-goods-img"></image>
								<view class="s-goods-center">
									<view class="s-goods-name">{{item.product_to.name}}</view>
									<view class="s-goods-attr" v-if="item.specs">{{item.specs}}</view>
								</view>
								<view class="s-price-right">
									<view>￥{{item.specs_to.money}}</view>
									<view>x{{item.num}}</view>
								</view>
							</view>
						</s-list-cell>
					</block>
				</view>
				<s-list-cell :hover="false">
					<view class="s-padding s-flex">
						<view>商品总额</view>
						<view>￥{{info.total_money}}</view>
					</view>
				</s-list-cell>
				<s-list-cell :hover="false">
					<view class="s-padding s-flex">
						<view>配送费</view>
						<view>￥{{info.deliver_money}}</view>
					</view>
				</s-list-cell>
				<s-list-cell :hover="false" :lineLeft="false" padding="0">
					<view class="s-remark-box s-padding s-flex">
						<view>订单备注</view>
						<input type="text" v-model="comment" class="s-remark" placeholder="选填: 请先和商家协商一致" maxlength="30" placeholder-class="s-phcolor"></input>
					</view>
				</s-list-cell>
			</view>
			<view class="s-tabbar">
				<view class="s-flex-end s-color-red s-pr-20">
					<view class="s-black">实付金额: </view>
					<view class="s-size-26">￥</view>
					<view class="s-price-large">{{info.s_total_money}}</view>
				</view>
				<view class="s-pr25">
					<s-button type="danger" shape="circle" size="mini" @click="submit_cart_order_pay">确认支付</s-button>
				</view>
			</view>
		</view>	 
	</view>
</template>
<script>
	export default {
		data() {
			return {
				info:{},//页面数据
				comment:'',//备注
			}
		},
		onShow() {
			this.getCartSubmitOrder()
		},
		methods: {
			//跳转收货地址
			async address(){
				return await this.$s.uniApi.navigateTo({url:'../address/address'})
			},
			async getCartSubmitOrder(){
				this.info = await this.$s.model.cart.getCartSubmitOrder()
			},
			//购物车提交订单支付
			async submit_cart_order_pay(){
				await this.$s.uniApi.deliveryRelease()
				var dataV = {
					comment:this.comment
				}
				// #ifdef MP-WEIXIN
					dataV.pay_from = 2
					dataV.type = 1
				// #endif
				// #ifdef MP-TOUTIAO
					dataV.pay_from = 3
					dataV.type = 2
				// #endif
				const idData = await this.$s.model.cart.submitCartOrderPay(dataV)
				if(!idData.id){
					return
				}
				const data = await this.$s.model.order.wxOrderPay(idData)
				const resData = await this.$s.uniApi.requestPayment(data)
				// #ifdef MP-WEIXIN
					if(resData.errMsg === "requestPayment:ok"){
						await this.$s.uniApi.navigateBack({})
					}else{
						return this.$s.uniApi.showToast({title:'支付失败！'})
					}
				// #endif
				// #ifdef MP-TOUTIAO
					if(resData.code === 0){
						await this.$s.uniApi.navigateBack({})
					}else{
						return this.$s.uniApi.showToast({title:'支付失败！'})
					}
				// #endif
				
			}
		},
		//下拉刷新
		async onPullDownRefresh() {
			await this.getCartSubmitOrder()
			uni.stopPullDownRefresh()
		}
	}
</script>

<style lang="scss" scoped>
@import 'cart_submit_order.scss';
</style>
